package com.kbt.util.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;
import com.kbt.activity.R;

/**
 * lvyb-a
 * 重写Dialog
 */
public class LoadingDialog extends Dialog {

    private TextView tvMsg = null;
    private ImageView proIv = null;

    private AnimationDrawable animationDrawable = null;

    public LoadingDialog(Context c, String msg) {
        this(c, R.style.CustomProgressDialog, msg);
    }

    public LoadingDialog(Context context, int theme, String msg) {
        super(context, theme);
        // TODO Auto-generated constructor stub
        this.setContentView(R.layout.dialog_custom_layout);
        this.getWindow().getAttributes().gravity = Gravity.CENTER;
        tvMsg = (TextView) this.findViewById(R.id.custom_load_title);
        if (msg != null) {
            tvMsg.setText(msg);
        }
        proIv = (ImageView) this.findViewById(R.id.custom_load_iv);
        animationDrawable = (AnimationDrawable) proIv.getBackground();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        // TODO Auto-generated method stub
        if (!hasFocus) {
            dismiss();
        } else {
            animationDrawable.start();
        }
    }


}
